<!-- 
自动排课界面
-->
<!DOCTYPE html>
<html>

<head>
    <!-- {% load static %} -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>教师预约</title>

    <!-- <link rel="stylesheet" href="{% static 'layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static 'css/teacher_reserve.css' %}"> -->
    <link rel="stylesheet" href="{% static 'layui/css/layui.css' %}">
    <link rel="stylesheet" href="{% static 'css/automatic_class_scheduling.css' %}">

</head>

<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">智慧教室管理系统</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-md-inline-block">
                <a href="javascript:;">
                    <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg"
                         class="layui-nav-img">
                    <span id="username">{{ name }}</span>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="/user_center/">个人中心</a></dd>
                    <dd><a href="/logout/">退出登录</a></dd>
                </dl>
            </li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="/admin_userManagement/">用户管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="student/">学生</a></dd>
                        <dd><a href="teacher/">教师</a></dd>
                        {% if state == 4 %}
                            <dd><a href="college_admin/">院级管理员</a></dd>
                        {% endif %}
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="/classroom-basic-info/">教室基本信息管理</a>
                </li>
                <li class="layui-nav-item">
                    <a href="/admin_useInfo_new/">教室使用信息管理</a>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="/course-schedule/">教室排课管理</a>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="/adminreserve/">教室预约管理
                        <span class="layui-badge-dot"></span></a>
                </li>
            </ul>
        </div>
    </div>


    <div class="layui-body">

        <div class="basicInfoHeader">
            <p>自动排课</p>
        </div>

        <!-- 上传课程文件 -->
        {% if flag == 1 %}
        <button type="button" class="layui-btn" id="uploadFile" style="margin-left: 10px;">
            <i class="layui-icon">&#xe67c;</i>上传课程文件(excel)
        </button>
        {% endif %}

        <fieldset class="layui-elem-field">
            <!-- 课表 -->
            <ul class="layui-nav" style="background-color: #fff;">
                {% for list in lists %}
                    <li class="layui-nav-item">
                        <a href="javascript:;" style="color: black;">{{ list.title }}</a>
                        <dl class="layui-nav-child">
                            {% for data in list.list %}
                                {% if flag == 0 %}
                                    <dd>
                                        <a href="{% url "courseSchedule:building" %}?bid={{ data.bid }}">{{ data.name }}</a>
                                    </dd>
                                {% elif flag == 1 %}
                                    <dd><a href="javascript:;"
                                           onclick="reload_table({{ bid }}, {{ data.cid }})">{{ data.name }}</a>
                                    </dd>
                                {% endif %}
                            {% endfor %}
                        </dl>
                    </li>
                {% endfor %}
            </ul>
        </fieldset>
        <fieldset class="layui-elem-field">
            <table border="1" align="2" align="center" cellspacing="10" cellpadding="10" lay-filter="classScheduling"
                   class="layui-table" , id="c_table">
            </table>
        </fieldset>
    </div>
</div>

<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>

<script src="{% static 'layui/layui.js' %}"></script>
<script src="{% static 'jquery/jquery-3.2.1.js' %}"></script>
<script src="{% static 'layer/layer.js' %}"></script>


<script>
    //JS
    const bid = {{ bid }};

    layui.use(['element', 'layer', 'util', 'form', 'table'], function () {
        var element = layui.element,
            layer = layui.layer,
            util = layui.util,
            form = layui.form,
            table = layui.table,
            $ = layui.$;

        //头部事件
        util.event('lay-header-event', {
            //左侧菜单事件
            menuLeft: function (othis) {
                layer.msg('展开左侧菜单的操作', {
                    icon: 0
                });
            },
            menuRight: function () {
                layer.open({
                    type: 1,
                    content: '<div style="padding: 15px;">处理右侧面板的操作</div>',
                    area: ['260px', '100%'],
                    offset: 'rt' //右上角
                    ,
                    anim: 5,
                    shadeClose: true
                });
            }
        });

        //课程表
        table.render({
            elem: "#c_table",
            loading: false,
            height: "full-20",
            cols: [[
                {
                    field: "week",
                    title: "星期",
                    width: 80
                }, {
                    field: "mon",
                    title: "星期一"
                }, {
                    field: "tue",
                    title: "星期二"
                }, {
                    field: "wed",
                    title: "星期三"
                }, {
                    field: "thu",
                    title: "星期四"
                }, {
                    field: "fri",
                    title: "星期五"
                }, {
                    field: "sat",
                    title: "星期六"
                }, {
                    field: "sun",
                    title: "星期日"
                }
            ]]
        })

        //更新表格
        window.reload_table = function (bid, cid) {
            table.reload("c_table", {
                url: "{% url "courseSchedule:room" %}",
                method: "post",
                headers: {"X-CSRFToken": "{{ csrf_token }}"},
                page: false,
                where: {
                    "bid": bid,
                    "cid": cid
                },
                done: function (res, curr, count) {
                    if (!("flag" in res)) alert("未知错误");
                    else if (res["flag"] !== 0) alert(res["flag"]);
                }
            })
        }
    });


</script>


<script>
    //上传文件
    layui.use('upload', function () {
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#uploadFile' //绑定元素
            ,
            url: "{% url "courseSchedule:schedule" %}" //上传接口
            ,
            accept: "file",
            data: {"bid": bid},
            done: function (res) {
                if (!("flag" in res)) alert("未知错误");
                else if (res["flag"] !== 0) alert(res["flag"]);
                else alert("排课成功");
            },
            error: function () {
                alert("请求错误");
            }
        });
    });
</script>
<script>
    //判断当前登录的是谁
    $.ajax({
                url: "/user/",
                method: "get",
                success: function (response) {
                    if(response.msg === 'ok'){
                        $("#username").html(response.data.username)
                    } else {
                        window.location.href = '/login'
                    }
                },
                error: function (err) {
                    window.location.href = '/login'
                }
        })
</script>
</body>

<style>
    .layui-table-cell {
        height: auto;
    }
</style>

</html>